package org.csu.hospital.service;

import org.csu.hospital.domain.Medicine;
import org.csu.hospital.persistence.MedicineMapper;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@MapperScan("org.csu.hospital.persistence")
public class medicineService {
    @Autowired
    private MedicineMapper medicineMapper;

    //获取所有药品
    public List<Medicine> getAllMedicine(){
        return medicineMapper.getAllMedicine();
    }

    //获取药品总数量
    public int countMedicine(){
        return medicineMapper.countMedicine();
    }

    //增删改药品
    @Transactional
    public int insertMedicine(Medicine medicine){
        return medicine==null ? 0 : medicineMapper.insertMedicine(medicine);
    }

    @Transactional
    public int updateMedicine(Medicine medicine, int medicineId){
        if(medicineId == 0 )
            return 0;

        return medicineMapper.updateMedicine(medicine, medicineId);

    }

    @Transactional
    public int deleteMedicine(int medicineId){
        return medicineMapper.deleteMedicine(medicineId);
    }

    public List<Medicine> listAllMedicine(int before, int after){return medicineMapper.listAllMedicine(before, after);}

}
